<template>
  <div class="app-container">
    <!-- 自定义控制 -->
    <!-- 查询和其他操作 -->
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item v-if="this.$store.state.user.fsiteLevel==3" label="客户名称">
        <el-select
          disabled
          v-model="listQuery.fsiteNo"
          clearable
          filterable
          class="filter-item"
          placeholder="请选择客户名称"
        >
          <el-option
            v-for="item in fsiteNoBelongOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item v-else label="客户名称">
        <el-select
          v-model="listQuery.fsiteNo"
          clearable
          filterable
          class="filter-item"
          placeholder="请选择客户名称"
        >
          <el-option
            v-for="item in fsiteNoBelongOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="场景类型">
        <el-select
          v-model="listQuery.fscenetype"
          clearable
          class="filter-item"
          placeholder="请选择场景类型"
        >
          <el-option
            v-for="(key, value) in fscenetypeMap"
            :key="key"
            :label="key"
            :value="value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <!-- v-permission="['scene:userScene:read']" -->
        <el-button
        round size="medium"
          class="filter-item"
          :style="{background:buttonColor.lookup,color:buttonColor.color}"
          @click="handleFilter"
          >查找</el-button
        >
        <!--<el-button v-permission="['scene:userScene:create']" class="filter-item" type="primary" icon="el-icon-edit" @click="handleCreate">添加</el-button>-->
      </el-form-item>
    </el-form>

    <!-- 查询结果 -->
    <el-table
      :height="buttonColor.clientHeight"
      v-loading="listLoading"
      :data="list"
      :header-cell-style="tableColor"
      element-loading-text="正在查询中。。。"
      border
      fit
      highlight-current-row
    >
    <el-table-column align="center" :width="buttonColor.operationOne" label="操作" class-name="small-padding">
        <template slot-scope="scope">
          <div class="operationButton">
            <div :style="{ color: buttonColor.edit, cursor: 'pointer' }" @click="handleUpdate(scope.row)">
              <img src="../../../public/images/edit.png" />
              查看
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        :index="indexMethod"
        align="center"
        label="序"
        type="index"
      />
      <el-table-column align="center" label="场景编号" prop="fsceneno" />
      <el-table-column align="center" label="场景名称" prop="fscenename" />
      <el-table-column
        :formatter="formatSite"
        align="center"
        label="客户名称"
        prop="fsiteNo"
      />
      <el-table-column align="center" label="场景类型" prop="fscenetype">
        <template slot-scope="scope">
          <el-tag>{{ scope.row.fscenetype | fscenetypeFilter }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column align="center" label="范围级别" prop="frange">
        <template slot-scope="scope">
          <el-tag>{{ scope.row.frange | frangeFilter }}</el-tag>
        </template>
      </el-table-column>
      <!--<el-table-column :formatter="formatFairitem" align="center" label="空气项目" prop="fairitem"/>
      <el-table-column align="center" label="符号" prop="fwhere" />
      <el-table-column align="center" label="空气值" prop="fvalue" />-->
      <el-table-column
        align="center"
        label="执行日期"
        prop="fexecweekList"
        width="155"
      >
        <template slot-scope="scope">
          <el-tag
            v-for="fexecweek in scope.row.fexecweekList"
            :key="fexecweek"
            type="primary"
            style="margin-right: 20px"
          >
            {{ fexecweek | fexecweekFilter }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column
        :formatter="dateFormat2"
        align="center"
        label="执行时间"
        prop="fexectime"
      />
      <!--<el-table-column align="center" label="实验室编号" prop="fpointNo" />-->
      <el-table-column align="center" label="教师编号" prop="fteacherno" />
      <el-table-column
        :width="buttonColor.date"
        :formatter="dateFormat"
        align="center"
        label="修改时间"
        prop="fupddate"
      />
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
      @pagination="getList"
    />

    <!-- 添加或修改对话框 -->
    <el-dialog
      :close-on-click-modal="false"
      :visible.sync="dialogFormVisible"
      width="auto"
    >
    <template slot="title">
        <div :style="titleColor">{{ textMap[dialogStatus] }}</div>
      </template>
      <el-form
        ref="dataForm"
        :rules="rules"
        :model="dataForm"
        status-icon
        label-position="left"
        label-width="auto"
      >
        <el-row>
          <el-col :span="12">
            <el-form-item label="客户名称" prop="fsiteNo">
              <el-select
                v-model="dataForm.fsiteNo"
                :disabled="true"
                clearable
                filterable
                placeholder="请选择"
              >
                <el-option
                  v-for="item in fsiteNoBelongOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              label="场景名称"
              prop="fscenename"
            >
              <el-input v-model="dataForm.fscenename" :disabled="true" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item
              class="el-form-item-small"
              label="场景类型"
              prop="fscenetype"
            >
              <el-select
                v-model="dataForm.fscenetype"
                :disabled="true"
                class="filter-item"
                placeholder="请选择场景类型"
                @change="changeSceneType(dataForm.fscenetype)"
              >
                <el-option
                  v-for="(key, value) in fscenetypeMap"
                  :key="key"
                  :label="key"
                  :value="value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              class="el-form-item-small"
              label="范围级别"
              prop="frange"
            >
              <el-select
                v-model="dataForm.frange"
                :disabled="true"
                class="filter-item"
                placeholder="请选择范围级别"
                @change="changeRange()"
              >
                <el-option
                  v-for="(key, value) in frangeMap"
                  :key="key"
                  :label="key"
                  :value="value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <!--<el-col :span="10" style="padding-left: 80px">
            <el-form-item v-show="dataForm.fscenetype==2" label="空气项目" prop="fairitem" style="width: 250px">
              <el-select v-model="dataForm.fairitem" clearable filterable placeholder="请选择">
                <el-option
                  v-for="item in sTsAiritemOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"/>
              </el-select>
            </el-form-item>
          </el-col>-->
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item
              v-show="dataForm.fscenetype == 2"
              label="空气项目"
              prop="fairitem"
            >
              <el-select
                v-model="dataForm.fairitem"
                :disabled="true"
                clearable
                filterable
                placeholder="请选择"
              >
                <el-option
                  v-for="item in sTsAiritemOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              v-show="dataForm.fscenetype == 2"
              prop="fwhere"
            >
              <!--<el-input v-model="dataForm.fwhere"/>-->
              <el-select
                v-model="dataForm.fwhere"
                :disabled="true"
                class="filter-item"
                placeholder="符号"
              >
                <el-option
                  v-for="(key, value) in symbolOptions"
                  :key="key"
                  :label="key"
                  :value="value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              v-show="dataForm.fscenetype == 2"
              prop="fvalue"
            >
              <el-input v-model="dataForm.fvalue" :disabled="true" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item
              v-show="dataForm.fscenetype == 3"
              label="执行日期"
              prop="fexecweekList"
            >
              <el-select
                v-model="dataForm.fexecweekList"
                :disabled="true"
                clearable
                multiple
                placeholder="请选择"
              >
                <el-option label="全选" @click.native="selectAll" />
                <el-option
                  v-for="(key, value) in fexecweekOptions"
                  :key="key"
                  :label="key"
                  :value="value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              v-show="dataForm.fscenetype == 3"
              label="执行时间"
              prop="fexectime"
            >
              <el-time-picker
                v-model="dataForm.fexectime"
                :disabled="true"
                type="datetime"
                placeholder="选择日期时间"
                format="HH:mm"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-tabs type="border-card">
        <el-tab-pane label="设备列表">
          <div class="filter-container">
            <!--<el-button class="filter-item" type="primary" icon="el-icon-edit" @click="handleUpdate1">添加设备</el-button>--><!--handleCreate-->
            <el-table
              v-loading="listLoading"
              :data="dataForm.sTsEquipmentList"
              :header-cell-style="tableColor"
              element-loading-text="正在查询中。。。"
              border
              fit
              highlight-current-row
              height="30vh"
            >
              <el-table-column
                :index="indexMethod"
                align="center"
                label="序"
                type="index"
              />
              <el-table-column
                align="center"
                label="设备"
                prop="feuipmentname"
              />
              <el-table-column
                align="center"
                label="指令"
                prop="finstructions"
              />
              <!--<el-table-column align="center" width="140" label="操作" class-name="small-padding">
                <template slot-scope="scope">
                  <el-button type="danger" size="mini" @click="handleDelete1(scope.row)">删除</el-button>
                </template>
              </el-table-column>-->
            </el-table>
          </div>
        </el-tab-pane>
        <el-tab-pane label="楼层列表">
          <div v-show="dataForm.frange == 1" class="filter-container">
            <!--<el-button class="filter-item" type="primary" icon="el-icon-edit" @click="handleUpdate2(dataForm.fsiteNo)">添加楼层</el-button>-->
            <el-table
              v-loading="listLoading"
              :data="dataForm.atsPoints"
              :header-cell-style="tableColor"
              element-loading-text="正在查询中。。。"
              border
              fit
              highlight-current-row
              height="30vh"
            >
              <el-table-column
                :index="indexMethod"
                align="center"
                label="序"
                type="index"
              />
              <el-table-column
                align="center"
                label="楼层名称"
                prop="fpointName"
              />
              <!--<el-table-column align="center" width="140" label="操作" class-name="small-padding">
                <template slot-scope="scope">
                  <el-button type="danger" size="mini" @click="handleDelete2(scope.row)">删除</el-button>
                </template>
              </el-table-column>-->
            </el-table>
          </div>
        </el-tab-pane>
        <el-tab-pane label="实验室列表">
          <div v-show="dataForm.frange == 2" class="filter-container">
            <!--<el-button class="filter-item" type="primary" icon="el-icon-edit" @click="handleUpdate2(dataForm.fsiteNo)">添加实验室</el-button>-->
            <el-table
              v-loading="listLoading"
              :data="dataForm.atsPoints"
              :header-cell-style="tableColor"
              element-loading-text="正在查询中。。。"
              border
              fit
              highlight-current-row
              height="30vh"
            >
              <el-table-column
                :index="indexMethod"
                align="center"
                label="序"
                type="index"
              />
              <el-table-column
                align="center"
                label="实验室名称"
                prop="fpointName"
              />
              <!--<el-table-column align="center" width="140" label="操作" class-name="small-padding">
                <template slot-scope="scope">
                  <el-button type="danger" size="mini" @click="handleDelete2(scope.row)">删除</el-button>
                </template>
              </el-table-column>-->
            </el-table>
          </div>
        </el-tab-pane>
      </el-tabs>
      <div slot="footer" class="dialog-footer">
        <el-button round :style="{background:buttonColor.cancel,color:buttonColor.colorone}" @click="dialogFormVisible = false">取消</el-button>
        <el-button
          round
          v-if="dialogStatus == 'create'"
         :style="{background:buttonColor.confirm,color:buttonColor.color}"
          @click="createData"
          >确定</el-button
        >
        <el-button round v-else :style="{background:buttonColor.confirm,color:buttonColor.color}" @click="updateData">确定</el-button>
      </div>
    </el-dialog>
    <el-dialog
      :close-on-click-modal="false"
      :title="textMap[dialogStatus1]"
      :visible.sync="dialogFormVisible1"
    >
      <el-form
        ref="dataForm1"
        :rules="rules"
        status-icon
        label-position="left"
        label-width="110px"
        style="width: 400px; margin-left: 50px"
      >
        <el-form-item
          class="el-form-item-small"
          label="设备类型"
          prop="feuipmenttype"
          style="width: 250px"
        >
          <el-select
            v-model="feuipment"
            class="filter-item"
            placeholder="请选择设备类型"
            @change="getEqtActions(feuipment)"
          >
            <el-option
              v-for="item in sTsEquipmentDictOptions"
              :key="item.value"
              :label="item.label"
              :value="item"
            />
          </el-select>
        </el-form-item>
        <el-form-item
          class="el-form-item-small"
          label="设备指令"
          style="width: 250px"
        >
          <el-select
            v-model="action"
            class="filter-item"
            placeholder="请选择设备指令"
          >
            <el-option
              v-for="item in eqtActionOptions"
              :key="item.value"
              :label="item.label"
              :value="item"
            />
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button round @click="dialogFormVisible1 = false">取消</el-button>
        <el-button round :style="{background:buttonColor.confirm,color:buttonColor.color}" @click="addData">确定</el-button>
      </div>
    </el-dialog>
    <el-dialog
      :close-on-click-modal="false"
      :title="textMap[dialogStatus2]"
      :visible.sync="dialogFormVisible2"
    >
      <el-form
        ref="dataForm2"
        :rules="rules"
        :model="dataForm"
        status-icon
        label-position="left"
        label-width="110px"
        style="width: 400px; margin-left: 50px"
      >
        <el-table
          ref="multipleTable"
          :data="atsPoints"
          tooltip-effect="dark"
          style="width: 100%"
          @selection-change="handleSelectionChange2"
        >
          <el-table-column type="selection" width="55" />
          <el-table-column prop="fpointNo" label="实验室编号" width="120" />
          <el-table-column
            prop="fpointName"
            label="实验室名称"
            show-overflow-tooltip
          />
        </el-table>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button round :style="{background:buttonColor.cancel,color:buttonColor.colorone}" @click="dialogFormVisible2 = false">取消</el-button>
        <el-button round :style="{background:buttonColor.confirm,color:buttonColor.color}" @click="addData2">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listScenario,
  createScenario,
  updateScenario,
  deleteScenario,
  eqtActions,
} from "@/api/userScene";
import { fsiteOptionsByLevel, sTsEquipmentDictOptions } from "@/api/area";
import {
  sTsAiritemOptions,
  listPointByFsiteNo,
  listPointByFsiteNo2,
} from "@/api/airAlarm";
import Pagination from "@/components/Pagination";
import moment from "moment/moment";
import { tableColor, titleColor, buttonColor } from "@/filters/index";

const fscenetypeMap = {
  3: "定时场景",
  4: "手工场景",
};

const frangeMap = {
  0: "学校",
  1: "楼层",
  2: "实验室",
};

const symbolOptions = {
  ">=": ">=",
  "<=": "<=",
  ">": ">",
  "<": "<",
  "=": "=",
};

const fexecweekOptions = {
  1: "周一",
  2: "周二",
  3: "周三",
  4: "周四",
  5: "周五",
  6: "周六",
  7: "周日",
};

export default {
  name: "Alarm",
  components: { Pagination },
  filters: {
    fscenetypeFilter(type) {
      return fscenetypeMap[type];
    },
    frangeFilter(type) {
      return frangeMap[type];
    },
    fexecweekFilter(type) {
      return fexecweekOptions[type];
    },
  },
  data() {
    return {
      titleColor,
      buttonColor,
      multipleSelection: [],
      multipleSelection2: [],
      multiple2: [],
      list: null,
      total: 0,
      fsiteNoBelongOptions: null,
      sTsAiritemOptions: null,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 20,
        fariname: undefined,
        sort: "create_time",
        order: "desc",
      },
      fscenetypeMap,
      frangeMap,
      symbolOptions,
      fexecweekOptions,
      dataForm: {
        fsceneno: undefined,
        fairitem: undefined,
        fscenetype: undefined,
        frange: undefined,
        fwhere: undefined,
        fvalue: undefined,
        fexectime: undefined,
        fscenename: undefined,
        fsiteNo: undefined,
        fpointNo: undefined,
        fteacherno: undefined,
        fupddate: undefined,
        sTsEquipmentList: [],
        atsPoints: [],
        fexecweekList: [],
      },
      feuipment: "",
      action: null,
      sTsEquipmentDictOptions: [],
      eqtActionOptions: [],
      atsPoints: [],
      dialogFormVisible: false,
      dialogFormVisible1: false,
      dialogFormVisible2: false,
      dialogStatus: "",
      dialogStatus1: "",
      dialogStatus2: "",
      textMap: {
        update: "编辑",
        create: "创建",
      },
      tableColor,
      rules: {
        fscenename: [
          { required: true, message: "场景名称不能为空", trigger: "blur" },
        ],
        fsiteNo: [
          { required: true, message: "客户名称不能为空", trigger: "blur" },
        ],
        fscenetype: [
          { required: true, message: "场景类型不能为空", trigger: "blur" },
        ],
        frange: [
          { required: true, message: "范围级别不能为空", trigger: "blur" },
        ],
      },
      permissionDialogFormVisible: false,
      systemPermissions: null,
      assignedPermissions: null,
      permissionForm: {
        roleId: undefined,
        permIds: [],
      },
    };
  },
  created() {
    if(this.$store.state.user.fsiteLevel==3) {
      this.listQuery.fsiteNo = this.$store.state.user.fsiteNo
    }
    this.getList();
    fsiteOptionsByLevel(3).then((response) => {
      this.fsiteNoBelongOptions = response.data.data.list;
    });
    sTsAiritemOptions().then((response) => {
      this.sTsAiritemOptions = response.data.data.list;
    });
  },
  methods: {
    formatStatus: function (row, column) {
      return row.fsiteState === 1 ? "启用" : "禁用";
    },
    dateFormat(row, column) {
      const date = row[column.property];
      if (date === undefined || date === null || date === "") {
        return "";
      }
      // debugger
      return moment(date).format("YYYY-MM-DD HH:mm:ss");
    },
    dateFormat2(row, column) {
      const date = row[column.property];
      if (date === undefined || date === null || date === "") {
        return "";
      }
      // debugger
      return moment(date).format("HH:mm:ss");
    },
    formatSite: function (row, column) {
      for (let i = 0; i < this.fsiteNoBelongOptions.length; i++) {
        if (row.fsiteNo === this.fsiteNoBelongOptions[i].value) {
          return this.fsiteNoBelongOptions[i].label;
        }
      }
      return "";
    },
    formatFairitem: function (row, column) {
      for (let i = 0; i < this.sTsAiritemOptions.length; i++) {
        if (row.fairitem === this.sTsAiritemOptions[i].value) {
          return this.sTsAiritemOptions[i].label;
        }
      }
      return "";
    },
    handleSelectionChange2(val) {
      this.multipleSelection2 = val;
    },
    getEqtActions(feuipment) {
      this.eqtActionOptions = [];
      this.action = "";
      eqtActions(feuipment.value)
        .then((response) => {
          this.eqtActionOptions = response.data.data.list;
        })
        .catch(() => {
          this.eqtActionOptions = [];
        });
    },
    addData() {
      this.dialogFormVisible1 = false;
      for (var i in this.dataForm.sTsEquipmentList) {
        var eqt = this.dataForm.sTsEquipmentList[i];
        if (
          eqt.feuipmentid === this.feuipment.value &&
          eqt.faction === this.action.value
        ) {
          return;
        }
      }
      this.dataForm.sTsEquipmentList.push({
        feuipmentid: this.feuipment.value,
        feuipmentname: this.feuipment.label,
        faction: this.action.value,
        finstructions: this.action.label,
      });
    },
    addData2() {
      this.dialogFormVisible2 = false;
      for (var i in this.multipleSelection2) {
        var atsPoint = this.multipleSelection2[i];
        var canAdd = true;
        for (var j in this.dataForm.atsPoints) {
          if (atsPoint.fpointNo === this.dataForm.atsPoints[j].fpointNo) {
            canAdd = false;
            break;
          }
        }
        if (canAdd) {
          atsPoint.fwarringno = this.dataForm.fwarringno;
          this.dataForm.atsPoints.push(atsPoint);
          this.multiple2.push(atsPoint);
        }
      }
    },
    changeSceneType(fscenetype) {
      if (fscenetype === 1) {
        this.dataForm.fairitem = null;
        this.dataForm.fwhere = null;
        this.dataForm.fvalue = null;
      } else if (fscenetype === 2) {
        this.dataForm.fexecweekList = [];
        this.dataForm.fexectime = null;
      }
    },
    changeRange() {
      this.dataForm.atsPoints = [];
      this.multipleSelection2 = [];
    },
    formatDate(fexectime) {
      var strs = fexectime.split(" ");
      var dateStr =
        "Jan 01 " + strs[1] + ":" + strs[0] + ":00 CST 1970 GMT+0800";
      return new Date(dateStr);
    },
    getList() {
      this.listLoading = true;
      listScenario(this.listQuery)
        .then((response) => {
          this.list = response.data.data.list;
          this.list.forEach((v) => {
            if (v.fscenetype === 3) {
              v.fexectime = this.formatDate(v.fexectime);
            } else {
              v.fexectime = null;
            }
          });
          this.total = response.data.data.total;
          this.listLoading = false;
        })
        .catch(() => {
          this.list = [];
          this.total = 0;
          this.listLoading = false;
        });
    },
    handleFilter() {
      this.listQuery.page = 1;
      this.getList();
    },
    resetForm() {
      this.dataForm = {
        id: undefined,
        fsceneno: undefined,
        fscenename: undefined,
        fsiteNo: undefined,
        fairitem: undefined,
        fscenetype: undefined,
        frange: undefined,
        fwhere: undefined,
        fvalue: undefined,
        fexectime: undefined,
        fariname: undefined,
        fexecweekList: [],
        sTsEquipmentList: [],
        // eqtActionOptions: [],
        atsPoints: [],
      };
    },
    handleCreate() {
      this.resetForm();
      this.dialogStatus = "create";
      this.dialogFormVisible = true;
      this.$nextTick(() => {
        this.$refs["dataForm"].clearValidate();
      });
    },
    createData() {
      this.$refs["dataForm"].validate((valid) => {
        if (valid) {
          if (
            this.dataForm.fscenetype === "1" &&
            (this.dataForm.fexecweekList === undefined ||
              this.dataForm.fexecweekList.length === 0)
          ) {
            this.$notify.info({
              title: "失败",
              message: "执行日期至少选择一天",
            });
            return;
          }
          createScenario(this.dataForm)
            .then((response) => {
              response.data.data.fexectime = this.formatDate(
                response.data.data.fexectime
              );
              this.list.unshift(response.data.data);
              this.dialogFormVisible = false;
              this.$notify.success({
                title: "成功",
                message: "添加预设场景成功",
              });
            })
            .catch((response) => {
              this.$notify.error({
                title: "失败",
                message: response.data.msg,
              });
            });
        }
      });
    },
    handleUpdate(row) {
      this.dataForm = Object.assign({}, row);
      this.dataForm.fscenetype = row.fscenetype.toString();
      this.dataForm.frange = row.frange.toString();
      this.dialogStatus = "update";
      this.dialogFormVisible = true;
      this.$nextTick(() => {
        this.$refs["dataForm"].clearValidate();
      });
    },
    handleUpdate1() {
      sTsEquipmentDictOptions().then((response) => {
        // this.sTsEquipmentDictOptions = response.data.data.list
        this.sTsEquipmentDictOptions = [];
        // var equipmentDict = []
        for (const equipmentDict of response.data.data.list) {
          if (equipmentDict.value !== 1 && equipmentDict.value !== 2) {
            // 非单插和三插
            this.sTsEquipmentDictOptions.push(equipmentDict);
          }
        }
      });
      this.dialogStatus1 = "update";
      this.dialogFormVisible1 = true;
      this.feuipment = "";
      this.eqtActionOptions = [];
      this.action = "";
      this.$nextTick(() => {
        this.$refs["dataForm1"].clearValidate();
      });
    },
    handleUpdate2(fsiteNo) {
      if (fsiteNo == null) {
        this.$notify.info({
          title: "",
          message: "请先选择学校",
        });
        return;
      }
      if (this.dataForm.frange === "1") {
        listPointByFsiteNo2(fsiteNo).then((response) => {
          this.atsPoints = response.data.data.list;
        });
      } else if (this.dataForm.frange === "2") {
        listPointByFsiteNo(fsiteNo).then((response) => {
          this.atsPoints = response.data.data.list;
        });
      }
      this.dialogStatus2 = "update";
      this.dialogFormVisible2 = true;
      this.multipleSelection2 = [];
      this.$nextTick(() => {
        this.$refs["dataForm2"].clearValidate();
      });
    },
    updateData() {
      this.$refs["dataForm"].validate((valid) => {
        if (valid) {
          if (
            this.dataForm.fscenetype === "1" &&
            (this.dataForm.fexecweekList === undefined ||
              this.dataForm.fexecweekList.length === 0)
          ) {
            this.$notify.info({
              title: "失败",
              message: "执行日期至少选择一天",
            });
            return;
          }
          updateScenario(this.dataForm, this.$route.query.id)
            .then(() => {
              for (const v of this.list) {
                if (v.fsceneno === this.dataForm.fsceneno) {
                  const index = this.list.indexOf(v);
                  this.list.splice(index, 1, this.dataForm);
                  break;
                }
              }
              this.dialogFormVisible = false;
              this.$notify.success({
                title: "成功",
                message: "更新场景设定成功",
              });
            })
            .catch((response) => {
              this.$notify.error({
                title: "失败",
                message: response.data.msg,
              });
            });
        }
      });
    },
    handleDelete(row) {
      this.$confirm("是否要删除该预设场景", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        deleteScenario(row.fsceneno, row.fscenetype)
          .then((response) => {
            this.$notify.success({
              title: "成功",
              message: "删除预设场景成功",
            });
            const index = this.list.indexOf(row);
            this.list.splice(index, 1);
          })
          .catch((response) => {
            this.$notify.error({
              title: "失败",
              message: response.data.msg,
            });
          });
      });
    },
    handleDelete1(row) {
      this.dataForm.sTsEquipmentList.pop(row);
    },
    handleDelete2(row) {
      this.dataForm.atsPoints.pop(row);
    },
    indexMethod(index) {
      index = index + 1;
      return index;
    },
    selectAll() {
      if (this.dataForm.fexecweekList.length < 7) {
        this.dataForm.fexecweekList = [];
        for (var option in fexecweekOptions) {
          this.dataForm.fexecweekList.push(option);
        }
      } else {
        this.dataForm.fexecweekList = [];
      }
    },
  },
};
</script>
